<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>Mine</title>
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../css/iconfont.css" />
		<link rel="stylesheet" type="text/css" href="../css/own.css" />
		<style type="text/css">
			.headImg {
				padding: 8% 0px 13% 0px;
				background: url(../img/bg.jpeg);
				background-position: center center;
				background-size: 100% auto;
			}
			
			.touxiang {
				text-align: center;
			}
			
			.touxiang div {
				width: 4em;
				height: 4em;
				padding: 0px;
				border-radius: 50%;
				border: 2px solid white;
				color: gray;
				margin: 0px auto;
				margin-bottom: 5px;
			}
		</style>
	</head>

	<body>
		<div class="mui-content">

			<div class="headImg">
				<div class="touxiang">
					<div>
						<span id="touxiangimg" class="mui-icon mui-icon-person" style="font-size: 3.8em; color: white;"></span>
						<img id="trueimg" src="../img/bg.jpeg" style="width: 100%; height: 100%; border-radius: 50%;" />
					</div>
					<span id="touxiangword">请登录</span>
				</div>
			</div>

			<ul class="mui-table-view" style="margin-top: 10px;">
				<li class="mui-table-view-cell">
					<a id="myInfo" class="mui-navigate-right" href="../mine/myInfo-needtem.html">
						<span class="mui-icon  mui-icon mui-icon-compose"></span> 编辑资料
					</a>
				</li>

				<li class="mui-table-view-cell">
					<a class="mui-navigate-right" href="../mine/my-order-needtem.html">
						<span class="mui-icon iconfont icon-wodedingdan"></span> 我的订单
					</a>
				</li>
				<li class="mui-table-view-cell">
					<a id="changeaddress" class="mui-navigate-right" href="../mine/change-address-needtem.html">
						<span class="mui-icon iconfont icon-dizhi"></span> 常用地址
					</a>
				</li>
				<li class="mui-table-view-cell">
					<a id="qianbao" class="mui-navigate-right" href="../mine/money.html">
						<span class="mui-icon  mui-icon-email"></span> 我的钱包
					</a>
				</li>
				<li class="mui-table-view-cell">
					<a class="mui-navigate-right" href="../mine/change-psd-needtem.html">
						<span class="mui-icon mui-icon-locked"></span> 修改密码
					</a>
				</li>
				<li class="mui-table-view-cell">
					<a id="kefu" class="mui-navigate-right" href="#">
						<span class="mui-icon iconfont icon-xiaolian"></span> 客服中心 <span  class="" style="float: right; margin-right: 5%;line-height: 30px;">0731-85482199</span>
					</a>
				</li>
			</ul>

			<ul class="mui-table-view" style="margin-top: 20px;">

				<li class="mui-table-view-cell">
					<a class="mui-navigate-right" href="../mine/feedback-needtem.html">
						<span class="mui-icon mui-icon-gear"></span> 设置
					</a>
				</li>
			</ul>

			<ul id="logoutBtn" class="mui-table-view" style="margin-top: 20px;margin-bottom: 20px;">
				<li class="mui-table-view-cell" style="text-align: center;">
					<span style="color: indianred;">退出登录</span>
				</li>
			</ul>

		</div>
		<script type="text/javascript" src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/own.js"></script>
		<script type="text/javascript" charset="UTF-8">
			mui.init({
				swipeBack: false
				
						
			});
			var parentWebView;
			var touxiangimg;
			var logoutBtn;
			var trueimg;
			var touxiangword;
			mui.plusReady(function() {
				
				
				
/*						var first=null;  
mui.back=function(){  
  if(!first){  
    first=new Date().getTime();  
    mui.toast('再按一次退出爱笑恩!');  
  
    setTimeout(function(){  
      first=null;  
    },2000);  
  }else{  
    if(new Date().getTime()-first<2000){  
      plus.runtime.quit();  
   }  
 }  
};  */
			/*	window.addEventListener('refresh',function(){
					//alert(555);
				   plus.webview.currentWebview().reload();
				});*/
				
				//var ws = plus.webview.currentWebview();
				
				//alert(ws.id);
				
				
 
				
					parentWebView = plus.webview.currentWebview().parent();
					touxiangimg = document.getElementById('touxiangimg');
					logoutBtn = document.getElementById('logoutBtn');
					trueimg = document.getElementById('trueimg');
					touxiangword = document.getElementById('touxiangword');
					//检测是否已经登录
					trueimg.style.display = 'none';
					logoutBtn.style.display = 'none'
					touxiangimg.style.display = 'inline'
					touxiangword.style.color = 'indianred'
						//注册列表的点击事件
					addListevent();
					//点击头像事件
					addHeadevent();
					//接收登录成功事件
					window.addEventListener('loginSuccess', function() {
						//登出按钮显示出来 头像图片显示出来名字显示出来
						logoutBtn.style.display = 'block';
						touxiangimg.style.display = 'none';
						trueimg.style.display = 'inline';
						touxiangword.innerText = plus.storage.getItem("nickName");
						touxiangword.style.color = 'black';
					}, false);
					logoutBtn.addEventListener('tap', function() {
						var btnArray = ['否', '是'];
						mui.confirm('确认要退出登录吗？', '爱笑恩', btnArray, function(e) {
							if(e.index == 1) {
								//确定
								trueimg.style.display = 'none';
								logoutBtn.style.display = 'none';
								touxiangimg.style.display = 'inline';
								touxiangword.style.color = 'indianred';
								touxiangword.innerText = '请登录';
								localStorage.removeItem('user');
								mui.toast("退出登录")

								//发出退出登录给wishlish和cart页面
								var cartwebview = plus.webview.getWebviewById('barItem/cart.html');
								var xinyuandanwebview = plus.webview.getWebviewById('barItem/wishList.html');
								mui.fire(cartwebview, 'logout', {});
								mui.fire(xinyuandanwebview, 'logout', {})
							} else {
								//取消
							}
						});
					}, false)
				})
				//点击头像事件
			function addHeadevent() {
				//alert(1);
				//console.log('addHeadevent');
				//点击头像登录
				touxiangimg.addEventListener('tap', function() {
					if(!localStorage.getItem('user')) {
						pushWebView({
							webType: 'newWebview_First',
							id: 'mine/login.html',
							href: 'mine/login.html',
							aniShow: getaniShow(),
							title: "登录",
							isBars: false,
							barsIcon: '',
							extendOptions: {}
						})
					}
					//					else if(localStorage.getItem('user')){
					//						//alert(1)
					//						pushWebView({
					//							webType: 'newWebview_First',
					//							id: 'mine/myInfo.html',
					//							href: 'mine/myInfo.html',
					//							aniShow: getaniShow(),
					//							title: "个人资料",
					//							isBars: false,
					//							barsIcon: '',
					//							extendOptions: {}
					//						})
					//						
					//					}
				}, false);
			}
			//注册列表的点击事件
			function addListevent() {
				mui('.mui-table-view').on('tap', 'a', function() {
					var id = this.getAttribute('href');
					var href = this.href;
					var title = this.innerText;
					var isBars = false;
					var barsIcon = '';
					var aniShow = getaniShow();
					var oldId = id;
					//plus.storage.setItem("oldId", oldId);
					//检测已经存在sessionkey否者运行下面的登陆代码
					if(localStorage.getItem('user')) {} else {
						href = "mine/login.html";
						id = "mine/login.html";
						aniShow = 'slide-in-bottom';
						title = '登录';
					}
					if(this.id == 'changeaddress') {
						isBars = true;
						barsIcon = 'mui-icon iconfont ';
					}
					if(this.id == 'myInfo') {
						isBars = true;
						barsIcon = 'mui-icon iconfont icon-iconfont53';
					}
					pushWebView({
						webType: 'newWebview_First',
						id: id,
						href: href,
						aniShow: aniShow,
						title: title,
						isBars: isBars,
						barsIcon: barsIcon,
						extendOptions: {}
					})
				});
			}

			document.getElementById("kefu").addEventListener('tap', function() {
				var btnArray = ['拨打', '取消'];
				var Phone = "0731-85482199";
				mui.confirm('是否拨打 ' + Phone + ' ？', '提示', btnArray, function(e) {
					if(e.index == 0) {
						plus.device.dial(Phone, false);
					}
				});
			});
		</script>
	</body>

</html>